<template>
	<view class="index">
		<view class="tip">
			上传行政许可证书、品牌授权证书等
		</view>
		<view class="upload-wrapper" @click="upload">
			<uni-icons type="plusempty" class="icon" size="20" color="#ffffff"></uni-icons>
			<text>点击上传</text>
		</view>
		<view class="image-wrapper">
			<image class="img" :src="item" v-for="(item,index) in imageList" :key="index" mode="widthFix"></image>
		</view>

		<view class="submit" @click="submit">
			提交
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imageList: []
			}
		},
		onLoad(option) {
			if (option.list) {
				this.imageList = JSON.parse(option.list)
			}
		},
		methods: {
			upload() {
				const _this = this;
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], //从相册选择
					success: async function(res) { //idCard //bankCard //businessLicense
						const url = await _this.$uploadFn(res.tempFilePaths[0], 0, 'businessQualification', 0,
							true);
						_this.imageList.push(url);
					}
				});
			},
			submit() {
				let context = '';
				if (this.imageList.length) {
					context = JSON.stringify(this.imageList)
				}
				var pages = getCurrentPages();
				var prevPage = pages[pages.length - 2];
				if (prevPage == undefined || prevPage == null) return;
				prevPage.$vm.setBusinessQualification(context);
				uni.navigateBack()
			}
		},
		components: {

		}
	}
</script>

<style lang="scss" scoped>
	.index {
		height: 100%;
		overflow: auto;
		padding: 30rpx;
		padding-bottom: 150rpx;

		.tip {
			color: #666666;
			font-size: 32upx;
		}

		.upload-wrapper {
			height: 90rpx;
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			background-color: #0D8EFF;
			color: #fff;
			margin-top: 20rpx;

			.icon {
				margin-right: 10rpx;
			}
		}

		.image-wrapper {
			.img {
				width: 100%;
				margin-top: 20rpx;
				border-radius: 10rpx;
			}
		}

		.submit {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 90upx;
			display: flex;
			align-items: center;
			justify-content: center;
			background-color: #0D8EFF;
			color: #fff;
		}
	}
</style>